package pers.xuankai.connectmysql.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pers.xuankai.connectmysql.mapper.UserMapper;
import pers.xuankai.connectmysql.model.User;
import pers.xuankai.connectmysql.service.UserService;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper mapper;

    @Override
    public List<User> getAllUser() {
        return mapper.selectAllUser();
    }

    @Override
    public User getUser(Integer id) {
        return mapper.selectByPrimaryKey(id);
    }

    @Override
    public int addUser(String name, int birthYear, String sex) {
        User user = new User();
        user.setName(name);
        user.setBirthYear(birthYear);
        user.setSex(sex);
        return mapper.insert(user);
    }
}
